import os
import re
import unicodedata

from config import Config

def validate_email(txt):
    r1=r"^\w+[-_.]*[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$"
    if not re.findall(r1, txt):
        return False
    return True

def validate_ext(txt, ext):
    t = txt.rsplit(".")[-1]
    if t in ext:
        return True
    return False

def validate_img_ext(txt):
    return validate_ext(txt, Config.IMAGE_EXT)

def validate_video_ext(txt):
    return validate_ext(txt, Config.VIDEO_EXT)


def is_number(t):
    n = "0123456789"
    if not t:
        return False
    if t.count(".") == 0:
        if t[0] == "-":
            t = t[1:]
        for i in t:
            if i not in n:
                return False
    elif t.count(".") == 1:
        if t[0] == "-":
            t = t[1:]
        if t[0] == ".":
            return False
        t = t.replace(".", "")
        for i in t:
            if i not in n:
                return False
    else:
        return False
    return True